<?php

namespace app\agent\controller;

use app\common\Common;
use app\common\BaseHelper;

use think\Exception;
use think\Request;

/**
 * 管理员
 */
class Admin extends Base
{
    public function _initialize()
    {

        $this->exceptAction = ['ajaxAdminList'];
        parent::_initialize();

        $this->model = 'Agentuser';
    }

    public function index(){

        return $this->view->fetch();
    }

    public function ajaxAdminList(){
        $request = $this->request;
        $param = $request->param();
        $model = model($this->model);

        // 每页起始条数
        $start = $param['start'];
        // 每页显示条数
        $length = $param['length'];
        // 排序条件
        $columns = $param['order'][0]['column'];
        $order = $param['columns'][$columns]['data'].' '.$param['order'][0]['dir'];

        $where = [];
        if($param['search']['value']) {
            $filter = json_decode($param['search']['value'],true);
        }

        $list = $model->where($where)->limit($start, $length)->order($order)->select();
        $count = $model->where($where)->count();

        $result = [
            'status' => '1',
            'draw' => $param['draw'],
            'data' => $list,
            'recordsFiltered' => $count,
            'recordsTotal' => $count,
        ];

        return json($result);
    }

}